var status = 0;
var chicken = 0;
var chosen = 0;
var pet = 0;

function start() {
    status = -1;
    action(1, 0, 0);
}
 
function action(mode, type, selection) {
    if (mode == -1) {
        cm.dispose();
    } else {
        if (mode == 0) {
	    cm.sendOk("Well, byebye then!");
            cm.dispose();
            return;
        }
        if (mode == 1)
            status++;
        else
            status--;
        if (status == 0) {
		if (cm.itemQuantity(5000029) >= 1) {
			cm.sendYesNo("I see that you have a baby dragon\r\nDo you want it to evolve?\r\nYou will need 1 water of life\r\n(Please un-equip your pet before clicking yes, or you will dc)");
			chicken = 1;
		} else if (cm.itemQuantity(5000048) >= 1) {
			cm.sendYesNo("I see that you have a baby robo\r\nDo you want it to evolve?\r\nYou will need 1 water of life");
			chicken = 2;
		} else {
			cm.sendOk("You don't have a baby dragon or a baby robo");
			cm.dispose();
		}
	} else if (status == 1) {
		if (chicken == 1) {
			if (cm.itemQuantity(5180000) >= 1) {
				cm.sendSimple("Great, you have a water of life\r\n#b#L1#I want a Green Dragon! #i5000030##l\r\n#L2#I want a Red Dragon! #i5000031##l\r\n#L3#I want a Blue Dragon! #i5000032##l\r\n#L4#I want a Black Dragon! #i5000033##l#k");
			} else {
				cm.sendOk("You dont have a water of life!");
				cm.dispose();
			}
		} else {
			if (cm.itemQuantity(5180000) >= 1) {
				cm.sendSimple("Great, you have a water of life\r\n#b#L1#I want a Blue Robo! #i5000049##l\r\n#L2#I want a Red Robo! #i5000050##l\r\n#L3#I want a Green Robo! #i5000051##l\r\n#L4#I want a Golden Robo! #i5000052##l\r\n#L5#I want a Gorilla Robo! #i5000053##k");
			} else {
				cm.sendOk("You dont have a water of life!");
				cm.dispose();
			}
		}
	} else if (status == 2) {
		chosen = selection;
		if (chicken == 1) {
			pet = (5000029 + chosen);
			cm.sendYesNo("Are you sure you want a #i" + pet + "#?");
		} else {
			pet = (5000048 + chosen);
			cm.sendYesNo("Are you sure you want a #i" + pet + "#?");
		}
	} else if (status == 3) {
		if (cm.itemQuantity(pet) >= 1) {
			cm.sendOk("You already have that pet...");
			cm.dispose();
		} else {
			if (chicken == 1) {
				cm.gainItem(5000029, -1);
				cm.gainItem(pet, 1);
				cm.gainItem(5180000, -1);
				cm.sendOk("Enjoy your new pet!\r\nif there are problems, please report them to adminbas");
				cm.dispose();
			} else {
				cm.gainItem(5000048, -1);
				cm.gainItem(pet, 1);
				cm.gainItem(5180000, -1);
				cm.sendOk("Enjoy your new pet!\r\nif there are problems, please report them to adminbas");
				cm.dispose();
			}
		}
	} else {
		cm.dispose();
	}
    }
}
